<?php

/*
 * Created on Dec 7, 2013
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
class Level_model extends CI_Model {

	public function __construct() {
		$this->load->database();
	}
	
	public function get_level($id){
  		$query = $this->db->get_where('tb_level', array('id' => $id));
  		return $query->row_array();
	}
	
//	
//	public function set_bill($id = 0){
//		$data = array (
//			'l_type' => $this->input->post('type'),
//			'l_code' => $this->input->post('code'),
//			'l_value' => $this->input->post('value')
//		);
//		if($id > 0){
//			$this->db->where('id', $id);
//			$this->db->update('tbl_bill', $data); 
//		}else{
//			return $this->db->insert('tbl_bill', $data);
//		}
//	}

	public function get_level_byname($name){
  		$query = $this->db->get_where('tb_level', array('level_name' => $name));
  		return $query->row_array();
	}

	public function level_insert($arr){
		$this->db->insert('tb_level', $arr);
	}
	
	public function level_update($id, $arr){
		$this->db->where('id', $id);
		$this->db->update('tb_level', $arr);
	}
	
	public function level_delete($id){
		$this->db->where('id', $id);
		$this->db->delete('tb_level');
	}
	
	public function list_level($search, $limit = false, $offset = 0){
		if($limit){
			$this->db->limit($limit, $offset);
		}
		$query = $this->db->get('tb_level');
		return $query->result_array();
	}
	
	public function count_level($search){
		return $this->db->count_all_results('tb_level');
	}
}

